﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Business.SalePurchase;
using System.Windows;
using PJ.Business;
using Microsoft.Practices.Composite.Events;

namespace PJ.Presentation.SalePurchase
{
    public abstract class ShoppingCartItemListModel<TShoppingCartItemModel> : EntityFragmentListViewModel<TShoppingCartItemModel>
        where TShoppingCartItemModel: class, IShoppingCartItemModel
    {
        protected ShoppingCartItemListModel(IView view, IEventAggregator aggregator, IShoppingCartItemService service)
            : base(view, aggregator, service)
        {
        }

        public override void InitializingNewItem(PJ.Presentation.IBusinessObjectModel newItem)
        {
            base.InitializingNewItem(newItem);
            if (Items.Count == 0)
                ((IShoppingCartItemModel)newItem).Order = 10;
            else
            {
                double max = 0;
                foreach (IShoppingCartItemModel model in Items)
                    if (model.Order > max)
                        max = model.Order;

                ((IShoppingCartItemModel)newItem).Order = max + 10;
            }
        }

    }
}
